package org.huangrui.javase.basic;

/**
 * @Author hr
 * @Create 2025-11-06 21:56
 **/
public class T07YangHuiTriangle {
    public static void main(String[] args) {
        printTriangle(10);
    }
    public static void printTriangle(int n) {
        int[][] triangle = new int[n][];
        /*
        (1)n行有n个数字
        (2)每一行的第1个和最后一个元素都是1
        (3)从第三行开始, 对于非第一个元素和最后一个元素的元素
          triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j]
    */
        for (int i = 0; i < n; i++) {
            triangle[i] = new int[i+1];
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    triangle[i][j] = 1;
                } else {
                    triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
                }
                System.out.print(triangle[i][j] + "\t");
            }
            System.out.println();
        }
    }
}
